/**
 *
 * Copyright (C), 2002-2017, è½¦å›½ç½‘.
 */
package main;

import java.io.Serializable;

/**
 *
 * @author zhangweifeng
 * @version $Id: Page.java, v 0.1 2017年12月12日 下午3:03:12 zhangweifeng Exp $
 */
public class Page implements Serializable {

	/** */
	private static final long serialVersionUID = 1L;

	public Integer offset;

	public Integer limit;

	/**
	 * 当前页-从1开始
	 */
	public Integer currentPage;

	public Integer pageSize;

	public Integer pageCount;

	public Integer totalItem;

	public Integer getOffset() {
		return offset;
	}

	public void setOffset(Integer offset) {
		this.offset = offset;
	}

	public Integer getLimit() {
		return limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getPageCount() {
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public Integer getTotalItem() {
		return totalItem;
	}

	public void setTotalItem(Integer totalItem) {
		this.totalItem = totalItem;
		if (totalItem != null) {
			this.pageCount = totalItem / pageSize + 1;
		} else {
			this.pageCount = 0;
		}
	}

	/**
	 * limit #offset# , #limit#
	 * 
	 * @param offset
	 * @param limit
	 */
	public void setOffsetAndLimit(int offset, int limit) {
		this.offset = offset;
		this.limit = limit;
	}

	/**
	 * @param currentPage
	 *            页码-从1开始
	 * @param pageSize
	 *            页大小
	 */
	public void setCurrentPageAndPageSize(int currentPage, int pageSize) {
		if (currentPage < 1) {
			throw new RuntimeException("this currentPage must more than 0 !");
		}
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.offset = (currentPage - 1) * pageSize;
		this.limit = pageSize;
	}
}
